
//ajax获取机构数据
function bindOrg(selectID,orgLevel,orgType,selectdata){
	var infoUrl = projectPath + "share/getOrg.do";
	$.ajax({ 
		url: infoUrl,
		data: {"orglevel": orgLevel,
				"orgtype":orgType
			},
		dataType: "json",
		success: function(data){
			if(data.result == 1){   
				var dataStr = data.datas;				
				// 先清空控件数据
				$('#' + selectID).empty(); 

				var option = $("<option>").val("").text(""); 
				$('#' + selectID).append(option); 
				
				for (var i = 0; i < dataStr.length; i++) {
					var value = dataStr[i].orgCode;
					var text = dataStr[i].orgName;
					
					var option = $("<option>").val(value).text(text); 
					$('#' + selectID).append(option); 
				}	
				
				//选中下拉列表的值
				if(selectdata != ""){
					$('#' + selectID).val(selectdata);
				}
			}
    	}
	});
	
}

//ajax获取字典数据
function bindDict(selectID, dictcode, selectdata,pitemcode,async){
	var infoUrl = projectPath + "share/getDictDetail.do";
	if(async==undefined||async===""){
		async=true;
	}
	$.ajax({ 
		url: infoUrl,
		data: {"dictcode": dictcode,"pitemcode":pitemcode},
		async:async,
		dataType: "json",
		success: function(data){
			if(data.result == 1){   
				var dataStr = data.datas;
				
				// 先清空控件数据
				$('#' + selectID).empty(); 

				var option = $("<option>").val("").text(""); 
				$('#' + selectID).append(option); 
				
				for (var i = 0; i < dataStr.length; i++) {
					var value = dataStr[i].itemcode;
					var text = dataStr[i].itemname;
					
					var option = $("<option>").val(value).text(text); 
					$('#' + selectID).append(option); 
				}	
				
				//选中下拉列表的值
				if(selectdata != ""){
					$('#' + selectID).val(selectdata);
				}
			}
    	}
	});
}

//ajax获取流程数据
function bindDict1(selectID, dictcode, selectdata){
	var infoUrl = projectPath + "share/getDictDetail.do";
	
	$.ajax({ 
		url: infoUrl,
		data: {"dictcode": dictcode},
		dataType: "json",
		success: function(data){
			if(data.result == 1){   
				var dataStr = data.datas;
				
				// 先清空控件数据
				$('#' + selectID).empty(); 

				var option = $("<option>").val("").text(""); 
				$('#' + selectID).append(option); 
				
				for (var i = 0; i < dataStr.length; i++) {
					var value = dataStr[i].itemcode;
					var text = dataStr[i].itemname;
					
					var option = $("<option>").val(value).text(text); 
					$('#' + selectID).append(option); 
				}	
				
				//选中下拉列表的值
				if(selectdata != null){
					$('#' + selectID).val(selectdata).trigger("change");
				}
			}
  	}
	});
}


//ajax获取流程数据
function bindOrg(selectID, selectdata){
	var infoUrl = projectPath + "share/getOrg.do";
	
	$.ajax({ 
		method: 'post',
		url: infoUrl,
		dataType: "json",
		contentType: "application/json",
		success: function(data){
			if(data.result == 1){   
				var dataStr = data.datas;
				
				// 先清空控件数据
				$('#' + selectID).empty(); 

				var option = $("<option>").val("").text(""); 
				$('#' + selectID).append(option); 
				
				for (var i = 0; i < dataStr.length; i++) {
					var level = dataStr[i].orgLevel;
					var nbsp = "";
					for(var j = 1; j < level; j++)
						nbsp += "　";
					
					var value = dataStr[i].orgCode;
					var text = nbsp + dataStr[i].orgName;
					
					var option = $("<option>").val(value).text(text); 
					$('#' + selectID).append(option); 
				}	
				
				//选中下拉列表的值
				if(selectdata != null){
//					$('#' + selectID).val("oneLevelFlow");
				}
			}
		}
	});
}


function bindWaterway(selectID, orgcode, selectdata){

	var infoUrl = projectPath + "share/getwaterway.do";
	if(orgcode == undefined || orgcode == null || $.trim(orgcode) == ''){
		return;
	}
	$.ajax({ 
		url: infoUrl,
		data: {"orgcode": orgcode},
		dataType: "json",
		success: function(data){
			// 先清空控件数据
			$('#' + selectID).empty(); 

			var option = $("<option>").val("").text("--请选择水道--"); 
			$('#' + selectID).append(option); 
			
			if(data.result == 1){   
				var dataStr = data.datas;
				
				
				for (var i = 0; i < dataStr.length; i++) {
					var value = dataStr[i].waterwaycode;
					var text = dataStr[i].waterwayname;
					
					var option = $("<option>").val(value).text(text); 
					$('#' + selectID).append(option); 
				}	
				
				//选中下拉列表的值
				if(selectdata != ""){
					$('#' + selectID).val(selectdata);
				}
			}
    	}
	});
}

function bindMark(selectID, waterwaycode, selectdata){

	var infoUrl = projectPath + "share/getmark.do";
	
	$.ajax({ 
		url: infoUrl,
		data: {"waterwaycode": waterwaycode},
		dataType: "json",
		success: function(data){
			// 先清空控件数据
			$('#' + selectID).empty(); 

			var option = $("<option>").val("").text("--请选择航标--"); 
			$('#' + selectID).append(option); 
			
			if(data.result == 1){   
				var dataStr = data.datas;
				
				for (var i = 0; i < dataStr.length; i++) {
					var value = dataStr[i].navigationmarkcode;
					var text = dataStr[i].navigationmarkname;
					
					var option = $("<option>").val(value).text(text); 
					$('#' + selectID).append(option); 
				}	
				
				//选中下拉列表的值
				if(selectdata != ""){
					$('#' + selectID).val(selectdata);
				}
			}
    	}
	});
}

//绑定泊位数据
function bindBearth(selectID, orgcode, selectdata){

	$.ajax({ 
		method: 'post',
		url: projectPath + "share/getberthlist.do",
		data: JSON.stringify({"SLJGDM": orgcode}),
		dataType: "json",
		contentType: "application/json",
		success: function(data){
			if(data.total > 0){   
				var dataStr = data.rows;				
				// 先清空控件数据
				$('#' + selectID).empty(); 

				var option = $("<option>").val("").text(""); 
				$('#' + selectID).append(option); 
				
				for (var i = 0; i < dataStr.length; i++) {
					var value = dataStr[i].berthcode;
					var text = dataStr[i].berth;
					
					var option = $("<option>").val(value).text(text); 
					$('#' + selectID).append(option); 
				}	
				
 				//选中下拉列表的值
 				if(selectdata != ""){
 					$('#' + selectID).val(selectdata);
 				}
			}
		}
	});
}


function bindPort(selectID, param, selectdata){
	$.ajax({ 
		method: 'post',
		url: projectPath + "share/getportlist.do",
		data: JSON.stringify(param),
		dataType: "json",
		contentType: "application/json",
		success: function(data){
			if(data.result == 1){   
				var dataStr = data.datas;
				
				// 先清空控件数据
				$('#' + selectID).empty(); 

				var option = $("<option>").val("").text(""); 
				$('#' + selectID).append(option); 
				
				for (var i = 0; i < dataStr.length; i++) {
					var value = dataStr[i].portcode;
					var text = dataStr[i].portname;

					var option = $("<option>").val(value).text(text); 
					$('#' + selectID).append(option); 
				}	
				
				//选中下拉列表的值
				if(selectdata != null){
					$('#' + selectID).val(selectdata).trigger("change");
				}
			}
		}
	});
}
